package com.baikeyang.app.controller.api.ActivityTools.v1;

import com.baikeyang.common.bean.PageResult;
import com.baikeyang.common.bean.ResponseResult;
import com.baikeyang.common.bean.activity.SimpleActivityInfo;
import com.baikeyang.common.bean.activity.SimpleActivityUser;
import com.baikeyang.common.model.*;
import com.baikeyang.service.activity.IActivityInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author     : BaiKeyang
 * @Date       : Created in 2020/5/20 14:50
 * @Description:
 * @Modified By: 
 * @Version: $
 */
@RestController("activityToolsIndex")
@RequestMapping(value = "app/v1/activityTools")
public class IndexController {

    @Autowired
    private IActivityInfoService activityInfoService;

    @RequestMapping(value = "list")
    public PageResult getActivityInfos(Integer page) {
        PageResult pagers = new PageResult();
        Integer size = 5;
        Integer current = 1;

        if(null != page) {
            current = page;
            if(current < 1){current = 1;}
        }
        Page<ActivityInfo> pageParam = new Page<>(current, size);
        IPage<SimpleActivityInfo> pageResult = activityInfoService.getSimpleActivityInfoPage(pageParam);
        pagers.setData(pageResult.getRecords());
        pagers.setPager(current, pageResult.getTotal());
        pagers.setResult("success");
        return pagers;
    }

    @RequestMapping(value = "push", method = RequestMethod.POST)
    public ResponseResult push(ActivityInfo activityInfo) {
        System.out.println(activityInfo);
        return activityInfoService.saveActivityInfo(activityInfo);
        //return new ResponseResult(ExecuteConstants.EXECUTESTATUS.成功, ExecuteConstants.EXECUTEINFO.成功, ExecuteConstants.EXECUTECODE.CODE_20000);
    }

    @RequestMapping(value = "detail/{id}")
    public ResponseResult push(@PathVariable(value = "id") String id) {
        return activityInfoService.getActivityInfoById(id);
    }

    @RequestMapping(value = "join", method = RequestMethod.POST)
    public ResponseResult join(ActivityUserJoin activityUserJoin) {
        return activityInfoService.joinActivityByUserId(activityUserJoin);
    }

    @RequestMapping(value = "fav", method = RequestMethod.POST)
    public ResponseResult join(ActivityUserFav activityUserFav) {
        return activityInfoService.favActivityByUserId(activityUserFav);
    }

    @RequestMapping(value = "care", method = RequestMethod.POST)
    public ResponseResult care(ActivityUserCare activityUserCare) {
        return activityInfoService.careActivityByUserId(activityUserCare);
    }



    @RequestMapping(value = "join/list")
    public IPage<SimpleActivityInfo> join(String userId, Integer page) {
        PageResult pagers = new PageResult();
        Integer size = 5;
        Integer current = 1;

        if(null != page) {
            current = page;
            if(current < 1){current = 1;}
        }
        Page<SimpleActivityInfo> pageParam = new Page<>(current, size);
        return activityInfoService.getActivityUserJoins(pageParam, Long.parseLong(userId));
    }

    @RequestMapping(value = "fav/list")
    public IPage<SimpleActivityInfo> fav(String userId, Integer page) {
        PageResult pagers = new PageResult();
        Integer size = 5;
        Integer current = 1;

        if(null != page) {
            current = page;
            if(current < 1){current = 1;}
        }
        Page<SimpleActivityInfo> pageParam = new Page<>(current, size);
        return activityInfoService.getActivityUserFavs(pageParam, Long.parseLong(userId));
    }

    @RequestMapping(value = "care/list")
    public IPage<SimpleActivityUser> care(String userId, Integer page) {
        PageResult pagers = new PageResult();
        Integer size = 5;
        Integer current = 1;

        if(null != page) {
            current = page;
            if(current < 1){current = 1;}
        }
        Page<SimpleActivityUser> pageParam = new Page<>(current, size);
        return activityInfoService.getActivityUserCares(pageParam, Long.parseLong(userId));
    }





    @RequestMapping(value = "join/check", method = RequestMethod.POST)
    public ResponseResult joinCheck(String userId, Long activityId) {
        return activityInfoService.checkActivityUserJoin(Long.parseLong(userId), activityId);
    }

    @RequestMapping(value = "fav/check", method = RequestMethod.POST)
    public ResponseResult favCheck(String userId, Long activityId) {
        return activityInfoService.checkActivityUserFav(Long.parseLong(userId), activityId);
    }

    @RequestMapping(value = "care/check", method = RequestMethod.POST)
    public ResponseResult careCheck(String userId, Long careUserId) {
        return activityInfoService.checkActivityUserCare(Long.parseLong(userId), careUserId);
    }





    @RequestMapping(value = "join/remove")
    public ResponseResult removeJoin(String userId, Long activityId) {
        return activityInfoService.removeJoinActivityByUserId(userId, activityId);
    }

    @RequestMapping(value = "fav/remove")
    public ResponseResult removeFav(String userId, Long activityId) {
        return activityInfoService.removeFavActivityByUserId(userId, activityId);
    }

    @RequestMapping(value = "care/remove")
    public ResponseResult removeCare(String userId, Long careUserId) {
        return activityInfoService.removeCareActivityByUserId(userId, careUserId);
    }


}
